package com.chushouya.controller.manager.api;

import com.chushouya.common.annotations.AuthSkip;
import com.chushouya.common.constant.ServiceType;
import com.general.framework.core.schema.Response;
import com.chushouya.manager.dto.api.geocoder.GeoLocationDTO;
import com.chushouya.manager.dto.api.geocoder.LocationDTO;
import com.chushouya.manager.service.api.GeocoderApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(ServiceType.API+ "/geocoder")
@Api(tags = "位置接口接口")
public class GeocoderApiController {


    @Resource
    private GeocoderApiService geocoderApiService;

    @GetMapping("/geoLocation")
    @ApiOperation("获取当前地理位置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ip", value = "ip地址"),
            @ApiImplicitParam(name = "lat", value = "纬度"),
            @ApiImplicitParam(name = "lng", value = "经度")
    })
    @AuthSkip
    public Response<GeoLocationDTO> geoLocation(HttpServletRequest request,String ip, String lat, String lng) {
        return Response.success(geocoderApiService.geoLocation(request,ip, lat, lng));
    }

    @GetMapping("/ipLocation")
    @ApiOperation("获取当前IP位置")
    @AuthSkip
    public Response<GeoLocationDTO> ipLocation(HttpServletRequest request) {
        return Response.success(geocoderApiService.ipLocation(request));
    }

//    @GetMapping("/ipAddress")
//    @ApiOperation("获取当前IP地址")
//    @AuthSkip
//    public Response<String> ipAddress(HttpServletRequest request) {
//        return Response.success(geocoderApiService.ipAddress(request));
//    }

    @GetMapping("/location")
    @ApiOperation("获取当前地理位置经纬度")
    @AuthSkip
    public Response<LocationDTO> location(String address) {
        return Response.success(geocoderApiService.locationGeocoder(address));
    }



}
